package com.liao.quart;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;
@Slf4j
@Component
public class DataUpdateTask {
    @Autowired
    private SimpMessagingTemplate messagingTemplate;

    @Scheduled(cron ="*/5 * * * * *")
    public void updateData() {
        // 更新数据
        Date date =new Date();
        System.out.println(date);
        log.debug(String.valueOf(date));
        // 发送消息
        messagingTemplate.convertAndSend("/topic/data",date);
    }
}